#include <stdio.h>
#include <winsock2.h>
#pragma comment (lib, "wsock32.lib")

int main()
{
    WSADATA wsa_data;
    if(WSAStartup(MAKEWORD(2,0), &wsa_data) != 0)
    {
        printf("WSA Initialization failed!\n");
        WSACleanup();
        system("PAUSE");
        return 0;
    }

    int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    if(sock == -1)
    {
        printf("Socket creation failed.\n");
        WSACleanup();
        system("PAUSE");
        return 0;
    }

    sockaddr_in addr;
    addr.sin_family = AF_INET;
    addr.sin_addr.s_addr = INADDR_ANY;
    addr.sin_port = htons(7777);

    if( bind( sock, (sockaddr*) (&addr), sizeof(addr) ) == -1 )
    {
        printf("Unable to bind socket!\n");
        WSACleanup();
        system("PAUSE");
        return 0;
    }

    listen(sock, 1);

    int temp_sock = -1;
    while(temp_sock == -1)
    {
        printf("Waiting....\n");
        temp_sock = accept(sock, 0, 0);
    }
    sock = temp_sock;

    printf("Client connected!\n");

    char *msg = "Welcome to server\n";
    send(sock, msg, strlen(msg), 0);

    // Shutdown our socket
    shutdown(sock, SD_SEND);

    // Close our socket entirely
    closesocket(sock);

    // Cleanup Winsock
    WSACleanup();
    system("PAUSE");
    return 0;






}